package com.heima.article.controller.v1;

import com.heima.article.apis.ArticleSearchControllerApi;
import com.heima.article.service.ApArticleSearchService;
import com.heima.model.article.dtos.UserSearchDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/v1/article/search")
public class ArticleSearchController implements ArticleSearchControllerApi {

    @Autowired
    private ApArticleSearchService apArticleSearchService;
    /**
     * 搜索记录
     * @param userSearchDto
     * @return
     */
    @PostMapping("/load_search_history")
    public ResponseResult ApArticleSearchController(@RequestBody UserSearchDto userSearchDto) {
        return apArticleSearchService.findUserSearch(userSearchDto);
    }




    /**
     * 删除搜索记录
     * @param userSearchDto
     * @return
     */
    @PostMapping("/del_search")
    public ResponseResult delUserSearch(@RequestBody UserSearchDto userSearchDto){
        return apArticleSearchService.delUserSearch(userSearchDto);
    }

    /**
     * 清空搜索记录
     * @param userSearchDto
     * @return
     */
    @PostMapping("/clear_search")
    public ResponseResult clearUserSearch(@RequestBody UserSearchDto userSearchDto){
        return apArticleSearchService.clearUserSearch(userSearchDto);
    }


    @PostMapping("/load_hot_keywords")
    @Override
    public ResponseResult hotKeywords(@RequestBody UserSearchDto userSearchDto) {
        return apArticleSearchService.hotKeywords(userSearchDto.getHotDate());
    }

    /**
     * 联想搜索
     * @param userSearchDto
     * @return
     */
    @PostMapping("/associate_search")
    @Override
    public ResponseResult searchAssociate(@RequestBody UserSearchDto userSearchDto) {
        return apArticleSearchService.searchAssociate(userSearchDto);
    }

}
